﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace P2PTransmit
{
    public class TaskStateConveter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var state = (Modal.NetworkState) value;
            switch ( state )
            {
                case Modal.NetworkState.Error:
                    return "";
                case Modal.NetworkState.Finish:
                    return "";
                case Modal.NetworkState.Pause:
                    return "";
                case Modal.NetworkState.Transmitting:
                    return "";
                case Modal.NetworkState.WaitForAccept:
                    return "";
                default:
                    return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Modal.NetworkState.WaitForAccept;            
        }
    }
    public class SpeedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var val = (long) value;
            var kb = val / 1024;
            var mb = val / 1048576;
            if ( val == 0 )
            {
                return value;
            }
            else if( val > 1024 && val < 1048576 )
            {
                return $"{kb}Kb/s";
            }
            else
            {
                return $"{mb}Mb/s";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
    }
}
